import { IDENTIFY } from '../contants';

/**
 * 用户模型
 * @props username  用户名
 * @props avatar    头像
 * @props password  密码
 * @props mobile    手机号码
 * @props identify  身份标识
 * @props source    注册来源
 * @props openid    微信用户唯一ID
 * @props amount    拥有书币数量
 * @props readTime  阅读时长-毫秒数
 * @props tags      用户标签
 * @props remark    用户备注
 */
export default function (app) {
  const { STRING, INTEGER, DATE, ENUM, ARRAY, BOOLEAN } = app.Sequelize;
  const User = app.model.define('user', {
    username: { type: STRING(30), allowNull: false },
    avatar: STRING,
    password: STRING,
    mobile: { type: STRING(11), allowNull: true, unique: true },
    identity: { type: ENUM, values: Object.values(IDENTIFY), allowNull: true },
    source: STRING(12),
    openid: STRING(50),
    amount: INTEGER,
    readTime: INTEGER,
    hasExchange: BOOLEAN,
    tags: ARRAY(STRING(20)),
    remark: STRING(100),
    createdAt: DATE,
    updatedAt: DATE
  });

  return User;
}
